package com.tilas.service.impl;

import com.tilas.mapper.DepMapper;
import com.tilas.pojo.Dept;
import com.tilas.service.DepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DepServiceImpl implements DepService {

    @Autowired
    private DepMapper depMapper;

    @Override
    public List<Dept> findAll() {

        return depMapper.findAll();
    }

    @Override
    public int deleteById(Integer id) {
        return depMapper.deleteById(id);
    }

    @Override
    public void add(Dept dept) {
        //1.补全基础属性createTime和updateTime
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        //2.调用mapper接口方法插入数据
        depMapper.add(dept);
    }

    @Override
    public Dept findOne(Integer id) {
        return depMapper.findOne(id);
    }

    @Override
    public void upDate(Dept dept) {
        //1.补全基础属性createTime和updateTime
        dept.setUpdateTime(LocalDateTime.now());
        //2.调用mapper接口方法插入数据
         depMapper.upDate(dept);
    }

}
